package lanou.giftsay_01.main;

import android.graphics.drawable.Drawable;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import lanou.giftsay_01.fragment.main.CategoryFragment;
import lanou.giftsay_01.fragment.main.GuideFragment;
import lanou.giftsay_01.fragment.main.HotFragment;
import lanou.giftsay_01.fragment.main.MineFragment;
import lanou.giftsay_01.tools.BaseActivity;
import lanou.giftsay_01.R;

public class MainActivity extends BaseActivity {

    private RadioButton rbGuide , rbHot , rbCategory , rbMine;

    @Override
    protected int setLayout() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        RadioGroup rd = bindView(R.id.my_radioGroup);
        rbGuide = bindView(R.id.btn_1);
        rbHot = bindView(R.id.btn_2);
        rbCategory =bindView(R.id.btn_3);
        rbMine = bindView(R.id.btn_4);

        rd.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                FragmentManager fragmentManager = getSupportFragmentManager();
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                switch (checkedId) {
                    case R.id.btn_1 :
                        fragmentTransaction.replace(R.id.my_fragment , new GuideFragment());
                        break;
                    case R.id.btn_2 :
                        fragmentTransaction.replace(R.id.my_fragment , new HotFragment());
                        break;
                    case R.id.btn_3 :
                        fragmentTransaction.replace(R.id.my_fragment , new CategoryFragment());
                        break;
                    case R.id.btn_4 :
                        fragmentTransaction.replace(R.id.my_fragment , new MineFragment());
                        break;
                }
                fragmentTransaction.commit();
            }
        });

        rd.check(R.id.btn_1);

    }

    @Override
    protected void initDate() {
        Drawable dbGuide =  getResources().getDrawable(R.drawable.selector_guide);
        dbGuide.setBounds( 0 , 0 , 110 , 110);
        rbGuide.setCompoundDrawables(null , dbGuide , null , null);
        Drawable dbHot = getResources().getDrawable(R.drawable.selector_hot);
        dbHot.setBounds( 0 , 0 , 110 , 110);
        rbHot.setCompoundDrawables( null , dbHot , null , null);
        Drawable dbCateGory = getResources().getDrawable(R.drawable.selector_category);
        dbCateGory.setBounds( 0 , 0 , 110 , 110 );
        rbCategory.setCompoundDrawables( null , dbCateGory , null ,null);
        Drawable dbMine = getResources().getDrawable(R.drawable.selector_mine);
        dbMine.setBounds( 0 , 0 , 110 ,110 );
        rbMine.setCompoundDrawables( null , dbMine , null , null);


    }

}